#include<iostream>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include <queue>
using namespace std;
typedef long long ll;
ll cnt[105];
ll num[300];
int n;
map<ll, int> P;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> cnt[i], P[cnt[i]]++;

    num[105] = cnt[0];

    for (int i = 105;; i++)
    {
        ll c = num[i];
        if (c % 3 == 0 && P[c / 3])
        {
            P[c / 3]--;
            num[i + 1] = c / 3;
        }
        else if (P[c * 2])
        {
            P[c * 2]--;
            num[i + 1] = c * 2;
        }
        if (!num[i + 1])
            break;
    }

    for (int i = 105;; i--)
    {
        ll c = num[i];
        if (P[c * 3])
        {
            P[c * 3]--;
            num[i - 1] = c * 3;
        }
        else if (c % 2 == 0 && P[c / 2])
        {
            P[c / 2]--;
            num[i - 1] = c / 2;
        }
        if (!num[i - 1])
            break;
    }

    int i = 0;

    while (!num[i])i++;

    printf("%lld", num[i++]);

    while (num[i])printf(" %lld", num[i++]);

    printf("\n");


    return 0;
}